package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController(value = "userShopController") // 给Bean设置别名，避免与管理员端的controller名称冲突
@RequestMapping(value = "/user/shop")
@Slf4j
@Api(tags = "店铺相关接口")
public class ShopController {
    public static final String KEY_SHOP_STATUS = "SHOP_STATUS";
    // 注入redis模板对象
    @Autowired
    private RedisTemplate redisTemplate;

    /*查询店铺营业状态*/
    @GetMapping(value = "/status")
    @ApiOperation(value = "获取店铺状态方法")
    public Result<Integer> getStatus() {
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY_SHOP_STATUS);
        log.info("获取店铺状态,{}", status.equals(1) ? "营业中" : "已休息");
        return Result.success(status);
    }
}
